
/* This do-file replicates the results in the paper. 
	It requires the following user-written packages: frmttable, rdrobust
	Type findit [package name] and follow prompts to install them. */
	
frmttable, clear
clear *

* load programs for exporting results
do _programs.do

* covariate groups
global covars1 ccode2-ccode11 year_2-year_15
global covars2 $covars1 threshold_2-threshold_33


/** Table 1 **/

frmttable, clear
forval i = 1/4 {
	matrix r`i' = J(1,3,.)
	}
matrix s = J(1,4,.)

use data-main, clear
bys citycode year: egen no = count(cri)
bys citycode: egen min = min(no)
gen min5 = (min >= 5) & min ~= .
gen min10 = (min >= 10) & min ~= .
gen min20 = (min >= 20) & min ~= .
foreach x in salary_ppp city_pop_new {
	replace `x' = log(`x')
}
global basic i.threshold city_pop_new
qui {
	areg cri salary_ppp $basic i.year, cl(citycode) abs(citycode)
	storesfe 1 salary_ppp
	areg cri salary_ppp $basic i.year if min5 == 1, cl(citycode) abs(citycode)
	storesfe 2 salary_ppp
	areg cri salary_ppp $basic i.year if min10 == 1, cl(citycode) abs(citycode)
	storesfe 3 salary_ppp
	areg cri salary_ppp $basic i.year if min20 == 1, cl(citycode) abs(citycode)
	storesfe 4 salary_ppp
}
cmb_tbl_fe 4


/** Figure 1 **/

* panel (a)
use data-main, clear
collapse margin salary_ppp uniques, by(citycode year salary_group)
rdplot salary_ppp margin if margin < .1 & margin > -.1, p(3) ///
	nbins(20 20) kernel(tri) graph_options(title("") ///
	xtitle("Distance to the closest" "population-based salary threshold (%)", size(small)) ///
	ytitle("Average monthly mayor's salary ({c 0128} PPP)") ///
	legend(ring(0) pos(11) rows(2) size(vsmall)) graphregion(margin(0 0 0 0)) aspectratio(1) ///
	xsize(4) ysize(4.15))
* panel (b)
use data-main, clear
rdplot cri2 margin if uniques == 1 & margin < .1 & margin > -.1, ///
	kernel(tri) p(3) graph_options(title("") ///
	xtitle("Distance to the closest" "population-based unique salary threshold (%)", size(small)) ///
	ytitle("Procurement corruption risk [0-1]") ///
	legend(ring(0) pos(11) rows(2) size(vsmall)) graphregion(margin(0 0 0 0)) aspectratio(1) ///
	xsize(4) ysize(4.15)) nbins(20 12) covs($covars1)


/** Table 2 **/

frmttable, clear
forval i = 1/3 {
	matrix r`i' = J(1,3,.)
	}
matrix s = J(2,3,.)
use data-main, clear
qui {
	rdrobust cri2 margin if uniques == 1 & margin < 1, ///
		covs($covars1) vce(cluster citycode) all 
	stores 1
	rdrobust cri2 margin if non_uniques == 1 & margin < 1, ///
		covs($covars2) vce(cluster citycode) all
	stores 2
	rdrobust cri2 margin if margin < .5, ///
		covs($covars2) vce(cluster citycode) all
	stores 3	
}
cmb_tbl 3

	
/** Table 3 **/

frmttable, clear
forval i = 1/9 {
	matrix r`i' = J(1,3,.)
	}
matrix s = J(2,9,.)
use data-main, clear
keep if country == "Romania"
egen crinew = rowmean(corr_proc corr_singleb)
drop threshold_*
* treatment group
preserve
* new thresholds in 2018
gen p1 = (city_pop > 3000 & city_pop < 7000) if city_pop ~= . & comune == 1
gen p2 = (city_pop > 7000 & city_pop < 15000) if city_pop ~= . & comune == 1
gen p3 = (city_pop > 15000) if city_pop ~= . & comune == 1
gen p4 = (city_pop > 10000 & city_pop < 30000) & city_pop ~= . & oras == 1
gen p5 = (city_pop > 10000 & city_pop < 30000) & city_pop ~= . & muni == 1
gen p6 = (city_pop > 50000 & city_pop < 150000) & city_pop ~= . & muni == 1
gen margint = (city_pop-5000)/5000 if p1 == 1
replace margint = (city_pop-10000)/10000 if p2 == 1
replace margint = (city_pop-20000)/20000 if p3 == 1
replace margint = (city_pop-20000)/20000 if p4 == 1
replace margint = (city_pop-20000)/20000 if p5 == 1
replace margint = (city_pop-100000)/100000 if p6 == 1
keep if p1 == 1 | p2 == 1 | p3 == 1 | p4 == 1 | p5 == 1 | p6 == 1
gen threshold_c5k = (p1 == 1)
gen threshold_c10k = (p2 == 1)
gen threshold_c20k = (p3 == 1)
gen threshold_o20k = (p4 == 1)
gen threshold_m20k = (p5 == 1)
gen treat = (year >= 2018)
gen new = 1
tempfile new
save `new', replace
restore, preserve
* thresholds eliminated in 2018
gen r1 = (city_pop > 5000 & city_pop < 9000) if city_pop ~= . & comune == 1
gen r2 = (city_pop < 40000 & city_pop > 10000) if city_pop ~= . & muni == 1
gen r3 = (city_pop > 20000) if city_pop ~= . & oras == 1
gen margint = (city_pop-7000)/7000 if r1 == 1
replace margint = (city_pop-25000)/25000 if r2 == 1
replace margint = (city_pop-30000)/30000 if r3 == 1
keep if r1 == 1 | r2 == 1 | r3 == 1
gen threshold_c7k = (r1 == 1)
gen threshold_o30k = (r3 == 1)
gen treat = (year < 2018)
tempfile old
save `old', replace
restore
use `new', clear
append using `old'
foreach v of varlist threshold_* {
	replace `v' = 0 if `v' == .
}
replace new = 0 if new == .
qui {
	* no actual threshold
	rdrobust crinew margint if treat == 0, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 1
	* threshold exists
	rdrobust crinew margint if treat == 1, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 2
	* new thresholds only
	rdrobust crinew margint if new == 1 & year < 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 3
	rdrobust crinew margint if new == 1 & year >= 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 4
	* old eliminated thresholds 
	rdrobust crinew margint if new == 0 & year < 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 5
	rdrobust crinew margint if new == 0 & year >= 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 6
}
* control group
use data-main, clear
keep if country == "Romania"
egen crinew = rowmean(corr_proc corr_singleb)
drop threshold_*
gen c1 = (city_pop < 6000) if city_pop ~= . & comune == 1
gen c2 = (city_pop < 30000) if city_pop ~= . & oras == 1
gen c3 = (city_pop > 25000 & city_pop < 75000) if city_pop ~= . ///
	& muni == 1
gen marginc = (city_pop-3000)/3000 if c1 == 1
replace marginc = (city_pop-10000)/10000 if c2 == 1
replace marginc = (city_pop-50000)/50000 if c3 == 1
keep if c1 == 1 | c2 == 1 | c3 == 1
gen threshold_c3k = (c1 == 1)
gen threshold_c10k = (c2 == 1)
qui {
	* pre-2018
	rdrobust crinew marginc if year < 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 7
	* post-2018
	rdrobust crinew marginc if year >= 2018, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 8
	* all years
	rdrobust crinew marginc, ///
		covs(threshold_*) vce(cluster citycode) all
	stores 9
}
cmb_tbl 9

* end